import os
import tempfile
from dataclasses import dataclass

@dataclass
class TempFileWriter:
    ext: str

    def write_temp_file(self, rd) -> str:
        try:
            with tempfile.NamedTemporaryFile(delete=False, suffix=self.ext) as audio_file:
                audio_file.write(rd.read())
                return audio_file.name
        except Exception as e:
            raise RuntimeError(f"ffmpeg create temp file: {e}")
